package com.xncoding.netty.socket.netty03;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class ByteEncoder extends MessageToByteEncoder<Object> {
    /**
     *  根据自己的需求设定
     * @param ctx
     * @param user 可以是自定义对象
     * @param out
     * @throws Exception
     */
    @Override
    protected void encode(ChannelHandlerContext ctx, Object user, ByteBuf out) throws Exception {
//        out.writeInt(user);
//        out.writeFloat()
        out.writeBytes(user.toString().getBytes());
    }
}
